package com.ocean.client.extension.security.service;

import com.ocean.client.extension.security.core.UmsMemberDetails;
import com.ocean.client.service.IUmsMemberService;
import com.ocean.core.util.constants.ConstantsAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 用户验证处理
 *
 * @author zhang
 * @since 2022-8-16
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private IUmsMemberService iUmsMemberService;

    /**
     * 授权
     *
     * @param username username
     * @return 用户信息
     */
    @Override
    public UserDetails loadUserByUsername(String username) {
        UmsMemberDetails memberDetails = iUmsMemberService.selectUserByUsername(username);
        if (memberDetails != null) {
            return memberDetails;
        }
        throw new UsernameNotFoundException(ConstantsAttribute.PASSWORD_ERROR);
    }
}
